@tool
@icon("../icons/history_state.svg")
class_name State_History
extends State

#region 属性
@export var deep:bool = false
var history:SavedState = null
#endregion
#region 字段
@export_node_path("State") var default_state:NodePath:
	set(value):
		default_state = value
		update_configuration_warnings()
#endregion
#region 信号
#endregion

#region 基类方法
func save(saved_state:SavedState,child_levels:int = -1):
	var state = SavedState.new()
	state.history = history
	saved_state.add_substate(self,state)
func restore(saved_state:SavedState,child_levels:int = -1):
	var state = saved_state.get_substate_or_null(self)
	if state:
		history = state.history
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _get_configuration_warnings() -> PackedStringArray:
	var warnings := super._get_configuration_warnings()
	var parent_state := get_parent()
	if not parent_state is State_Compound:
		warnings.append("State_History必须是State_Compound的子节点")
	var default_state_node := get_node_or_null(default_state)
	if not default_state_node is State:
		warnings.append("默认节点没有设置或不是State")
	else:
		if not get_parent().is_ancestor_of(default_state_node):
			warnings.append("默认节点必须是State_History父节点的子节点")
	if get_child_count() > 0:
		warnings.append("State_History不能有子节点")
	return warnings
#endregion
